package com.chenchao.javafile;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @encoding : UTF-8
 * @Time : 2020/11/15 16:34
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.javaFile.Test6.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * IO流异常处理
 */
public class Test6 {
    public static void main(String[] args) {
        File file = new File("myjava01/src/fo/aa.txt");
        //从JDK7开始，这种写法会自动帮你关对象
        //减少代码冗余性
        try (
                FileReader fileReader = new FileReader(file);
                FileWriter fileWriter = new FileWriter(file);)
        {
            System.out.println((char)fileReader.read());
            fileWriter.write("fdfv");
            fileWriter.write("fdfv");
            fileWriter.write("fdfv");
            fileWriter.write("fdfv");
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
